<?php

require_once dirname(__FILE__).'/../lib/giftboxGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/giftboxGeneratorHelper.class.php';

/**
 * giftbox actions.
 *
 * @package    sf_sandbox
 * @subpackage giftbox
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class giftboxActions extends autoGiftboxActions
{

      protected function buildCriteria()
  {
    if (is_null($this->filters))
    {
      $this->filters = $this->configuration->getFilterForm($this->getFilters());
    }

    $criteria = $this->filters->buildCriteria($this->getFilters());

    $this->addSortCriteria($criteria);

    $event = $this->dispatcher->filter(new sfEvent($this, 'admin.build_criteria'), $criteria);
    $criteria = $event->getReturnValue();

    if($this->getUser()->hasCredential('partner') and !$this->getUser()->isSuperadmin() )
    {
        $criteria->add(sfGuardUserPeer::PARTNER_ID,$this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
        $criteria->addJoin(sfGuardUserPeer::ID,GiftboxPeer::TO_ID);
    }

    return $criteria;
  }

}
